﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Entity;
using Command;

namespace DAL
{
    public class X_Or
    {
        //查询订单
        public static List<OrderInformatica> GetOrderinfo(int uid) {
            string sql = string.Format("select *,sheng=(select name from area where codeID=s.saveid),shi=(select name from area where codeID=s.cityid),xian=(select name from area where codeID=s.Countyid) from OrderInformatica  o  ,ShoppingAddress s where o.OrderAddress=s.AddressId and o.Userid={0}",uid);
            List<OrderInformatica> list = new List<OrderInformatica>();
            SqlDataReader dr = DBHelper.Getdata(sql); 
            while(dr.Read())
            {
                OrderInformatica or = new OrderInformatica();
                or.OrderId = (string)dr["OrderId"];
                or.OrderState = (int)dr["OrderState"];
                or.OrderAmount = (decimal)dr["OrderAmount"];
                or.OrderDate = (DateTime)dr["OrderDate"];
                or.sheng = (string)dr["sheng"];
                or.shi = (string)dr["shi"];
                or.xian = (string)dr["xian"];
                list.Add(or);
            }
            dr.Close();
            return list;
        }
        //查询订单详情
        public static List<OrderDetails> Getorderdetail(string oid)
        {
            string sql = string.Format("select * from orderdetails o,bookinformatica b where o.bookid=b.bookid and o.orderid='{0}'",oid);
            List<OrderDetails> list = new List<OrderDetails>();
           SqlDataReader dr = DBHelper.Getdata(sql);
           while (dr.Read())
           {
               OrderDetails o = new OrderDetails();
               o.bookname = (string)dr["bookname"];
               o.Count = (int)dr["Count"];
               o.BookPrice = (decimal)dr["BookPrice"];
               o.BookId = (int)dr["BookId"];
               list.Add(o);
           }
           dr.Close();
           return list;
        }
        //评价回显
        public static List<BookInformatica> Pjhx(string bookid)
        {
            string sql = string.Format("select * from BookInformatica where bookid='{0}'",bookid);
            List<BookInformatica> list = new List<BookInformatica>();
            SqlDataReader dr = DBHelper.Getdata(sql);
            while (dr.Read())
            {
                BookInformatica b = new BookInformatica();
                b.BookId = (int)dr["BookId"];
                b.BookPicture = (string)dr["BookPicture"];
                b.BookName = (string)dr["BookName"];
                b.BookPrice = (decimal)dr["BookPrice"];
                list.Add(b);
            }
            dr.Close();
            return list;
        }
        //添加评价
        public static int Inserpj(int bookid,int userid,string cv,string dt)
        {
            string sql = string.Format("insert into Comment  ([BookId],[UserId],[CommentValue],[CommentState],[CommentDate]) values ('{0}','{1}','{2}','{3}','{4}')",bookid,userid,cv,1,dt);
            return DBHelper.Adddata(sql);
        }
    }
}
